﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

using Framework.Graphics;

namespace Framework.GameStateManagment
{
    public class Input
    {
        private static KeyboardState _KS;
        private static MouseState _MS;
        private static int _Richtung;
        private static Vector2 _Movement;
        private static float _Speed;

        public static Vector2 Movement
        {
            get { return _Movement; }
            set { _Movement = value; }
        }

        public static void Init()
        {
            _Movement = new Vector2(0, 0);
            _KS = Keyboard.GetState();
            _MS = Mouse.GetState();
            _Richtung = 1;
            _Speed = 2;
        }

        public static void Update()
        {
            if (GameStateManagment.GameState == 3)
            {
                _Speed = 0;
            }
            else
            {
                _Speed = 2;
            }

            _KS = Keyboard.GetState();
            _MS = Mouse.GetState();

            #region Richtungen

            if (_KS.IsKeyDown(Keys.W) && _KS.IsKeyUp(Keys.S) && _KS.IsKeyUp(Keys.A) && _KS.IsKeyUp(Keys.D))
            {
                _Richtung = 1;
            }
            if (_KS.IsKeyDown(Keys.S) && _KS.IsKeyUp(Keys.W) && _KS.IsKeyUp(Keys.A) && _KS.IsKeyUp(Keys.D))
            {

                _Richtung = 5;
            }
            if (_KS.IsKeyDown(Keys.A) && _KS.IsKeyUp(Keys.W) && _KS.IsKeyUp(Keys.S) && _KS.IsKeyUp(Keys.D))
            {
                _Richtung = 7;
            }
            if (_KS.IsKeyDown(Keys.D) && _KS.IsKeyUp(Keys.W) && _KS.IsKeyUp(Keys.S) && _KS.IsKeyUp(Keys.A))
            {
                _Richtung = 3;
            }

            // Diagonalen
            if (_KS.IsKeyDown(Keys.D) && _KS.IsKeyDown(Keys.W))
            {
                _Richtung = 2;
            }
            if (_KS.IsKeyDown(Keys.D) && _KS.IsKeyDown(Keys.S))
            {
                _Richtung = 4;
            }
            if (_KS.IsKeyDown(Keys.A) && _KS.IsKeyDown(Keys.W))
            {
                _Richtung = 8;
            }
            if (_KS.IsKeyDown(Keys.A) && _KS.IsKeyDown(Keys.S))
            {
                _Richtung = 6;
            }

            #endregion

            if (KS.IsKeyDown(Keys.W))
            {
                _Movement.Y += _Speed;
            }
            if (KS.IsKeyDown(Keys.S))
            {
                _Movement.Y -= _Speed;
            }
            if (KS.IsKeyDown(Keys.A))
            {
                _Movement.X += _Speed;
            }
            if (KS.IsKeyDown(Keys.D))
            {
                _Movement.X -= _Speed;
            }

            Camera.Update(MovementNow());
        }

        public static int Richtung()
        {
            return _Richtung;
        }

        public static KeyboardState KS
        {
            get { return _KS; }
        }

        public static MouseState MS
        {
            get { return _MS; }
        }

        public static Vector2 MovementNow()
        {
            Vector2 Temp = new Vector2(0, 0);
            _Speed = 2f;

            if (KS.IsKeyDown(Keys.W))
            {
                Temp.Y += _Speed;
            }
            if (KS.IsKeyDown(Keys.S))
            {
                Temp.Y -= _Speed;
            }
            if (KS.IsKeyDown(Keys.A))
            {
                Temp.X += _Speed;
            }
            if (KS.IsKeyDown(Keys.D))
            {
                Temp.X -= _Speed;
            }

            return Temp;

        }
    }
}
